package no.uib.hplims.models;

import java.util.ArrayList;

import javax.persistence.Entity;

import org.vaadin.appfoundation.persistence.data.AbstractPojo;

@Entity
public class Experiment extends AbstractPojo {
	private static final long serialVersionUID = 2970344932140056597L;

	private String name = null;

	private ArrayList<Long> peptideIds = new ArrayList<Long>();

	private int numberOfPeptides = 0;

	private User owner = null;

	public Experiment() {
		name = "Experiment";
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public ArrayList<Long> getPeptideIds() {
		if (peptideIds == null) {
			peptideIds = new ArrayList<Long>();
		}
		return peptideIds;
	}

	public void setPeptideIds(ArrayList<Long> peptides) {
		this.peptideIds = peptides;
		if (this.peptideIds != null) {
			numberOfPeptides = this.peptideIds.size();
		} else {
			numberOfPeptides = 0;
		}
	}

	public void addPeptide(Peptide p) {
		if (!peptideIds.contains(p.getId())) {
			peptideIds.add(p.getId());
			numberOfPeptides++;
		}
	}

	public void addPeptide(Long p) {
		if (!peptideIds.contains(p)) {
			peptideIds.add(p);
			numberOfPeptides++;
		}
	}

	public void removePeptide(Peptide p) {
		if (peptideIds.contains(p.getId())) {
			peptideIds.remove(p.getId());
			numberOfPeptides--;
		}
	}

	public void removePeptide(Long id) {
		if (peptideIds.contains(id)) {
			peptideIds.remove(id);
			numberOfPeptides--;
		}
	}

	public int getNumberOfPeptides() {
		return numberOfPeptides;
	}

	public User getOwner() {
		return owner;
	}

	public void setOwner(User owner) {
		this.owner = owner;
	}

	@Override
	public String toString() {
		return name;
	}

}
